package com.github.io.websocket;

import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;

import java.util.Map;

/**
 * @author liry
 * @version 1.0
 * @date Created on 2022/8/24 10:48
 * Description: 自定义 WebSocketHandshakeInterceptor 拦截器
 *              Socket建立连接（握手）和断开 
 */
public class WebSocketHandshakeInterceptor extends HttpSessionHandshakeInterceptor {
    @Override
    public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
        System.out.println("before handshake 。。。。。。。。。。。。。。");
        return super.beforeHandshake(request, response, wsHandler, attributes);
    }

    @Override
    public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception ex) {
        System.out.println("after handshake 。。。。。。。。。。。。。。");
        
        super.afterHandshake(request, response, wsHandler, ex);
    }
}
